﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Serialization;

namespace FourPartHarmony3 {
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();

            Closed += MainWindow_Closed;
        }

        private string ApplicationName = "FourPartHarmony3";
        GrandStaffControl mGrandStaffChordList   = new GrandStaffControl();
        GrandStaffControl mGrandStaffRealization = new GrandStaffControl();
        ChordType mChordType = new ChordType();
        Realization mRealization = new Realization();
        List<Chord> mChordCandidateList = new List<Chord>();
        bool mLoaded = false;
        private MeterStruct mMeter;
        MidiOutput mMidiOutput = new MidiOutput();
        ChordPlayer mChordPlayer;

        void MainWindow_Closed(object sender, EventArgs e) {
            mMidiOutput.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            mMidiOutput.Open(0);
            mChordPlayer = new ChordPlayer(mMidiOutput);

            mGrandStaffChordList.Initialize(mChordListCanvas);
            mGrandStaffChordList.ChooseChord = OnChordListScoreChooseChord;
            mGrandStaffRealization.Initialize(mRealizationCanvas);
            mGrandStaffRealization.ChooseChord = OnRealizationScoreChooseChord;

            mLoaded = true;

            mChordType.positionOfAChord = PositionOfAChord.密;
            mChordType.musicKey = MusicKey.Cdur;

            InitializeKeyComboBox();
            UpdateInternalKeyComboBox();
            UpdateBorrowedKeyComboBox();
            UpdateKeyRelatedCheckBoxState();

            UpdateChordList();
        }

        private void OnChordListScoreChooseChord(Chord c) {
            mTextBoxChordListVerdict.Text = mGrandStaffChordList.GetSelectedChord().GetVerdictText();
            mChordPlayer.Play(c);
        }

        private void OnRealizationScoreChooseChord(Chord c) {
            mTextBoxRealizationVerdict.Text = mGrandStaffRealization.GetSelectedChord().GetVerdictText();
            mChordPlayer.Play(c);
        }

        /// <summary>
        /// 起動時に1回だけ呼ぶ。
        /// </summary>
        private void InitializeKeyComboBox() {
            mComboBoxKey.Items.Clear();

            foreach (var k in MusicKeyInfo.MainKeyCandidates) {
                var mki = new MusicKeyInfo(k, k);
                mComboBoxKey.Items.Add(mki.GetString());
            }
            mComboBoxKey.SelectedIndex = 0;
        }

        private void UpdateInternalKeyComboBox() {
            mComboBoxInternalKey.Items.Clear();
            var mainkey = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];

            for (int i=0; i<(int)KeyRelation.NUM; ++i) {
                var kr = (KeyRelation)i;
                var mki = new MusicKeyInfo(mainkey, kr);
                if (mki.InternalKey == MusicKey.Invalid) {
                    var cbi = new ComboBoxItem();
                    cbi.Content = "invalid";
                    cbi.Visibility = Visibility.Collapsed;
                    mComboBoxInternalKey.Items.Add(cbi);
                } else {
                    mComboBoxInternalKey.Items.Add(string.Format("{0} ({1})", mki.GetKeyRelationString(), mki.GetString()));
                }
            }
            mComboBoxInternalKey.SelectedIndex = 0;
        }

        private void UpdateBorrowedKeyComboBox() {
            mComboBoxBorrowedKey.Items.Clear();
            var mainkey = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];
            var kri = (KeyRelation)mComboBoxInternalKey.SelectedIndex;
            var mki = new MusicKeyInfo(mainkey, kri);

            for (int i = 0; i < (int)KeyRelation.NUM; ++i) {
                var krb = (KeyRelation)i;
                var mkb = new MusicKeyInfo(mki.InternalKey, krb);
                if (mkb.InternalKey == MusicKey.Invalid) {
                    var cbi = new ComboBoxItem();
                    cbi.Content = "invalid";
                    cbi.Visibility = Visibility.Collapsed;
                    mComboBoxBorrowedKey.Items.Add(cbi);
                } else {
                    mComboBoxBorrowedKey.Items.Add(string.Format("{0} ({1})", mkb.GetKeyRelationString(), mkb.GetString()));
                }
            }
            mComboBoxBorrowedKey.SelectedIndex = 0;
        }

        private void UpdateKeyRelatedCheckBoxState() {
            var mainkey = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];
            var kri = (KeyRelation)mComboBoxInternalKey.SelectedIndex;
            var krb = (KeyRelation)mComboBoxBorrowedKey.SelectedIndex;
            var mki = new MusicKeyInfo(mainkey, kri);
            var mkb = new MusicKeyInfo(mki.InternalKey, krb);

            if (mkb.IsMajor()) {
                // 長調
                mCheckBoxBorrowedMinorChord.IsEnabled = true;
                mCheckBoxNaturalMinor.IsChecked = false;
                mCheckBoxNaturalMinor.IsEnabled = false;
            } else {
                // 短調
                mCheckBoxBorrowedMinorChord.IsEnabled = false;

                if (mChordType.chordDegree == CD.V || mChordType.chordDegree == CD.V_V) {
                    mCheckBoxNaturalMinor.IsEnabled = true;
                } else {
                    mCheckBoxNaturalMinor.IsChecked = false;
                    mCheckBoxNaturalMinor.IsEnabled = false;
                }
            }
        }

        private void UpdateChordList() {
            if (!mLoaded) {
                return;
            }

            mChordCandidateList.Clear();

            var cl = ChordListFactory.Generate(mChordType);
            cl = mRealization.VerdictAndSort(cl, mGrandStaffRealization.GetSelectedChordIdx() + 1);
            mChordCandidateList = cl;

            mButtonAddSelectedChord.IsEnabled = (0 < cl.Count);

            mGrandStaffChordList.Update(GrandStaffControl.StaffType.ChooseChord, mMeter, mChordCandidateList);

            if (0 == mChordCandidateList.Count) {
                mTextBoxChordListVerdict.Text = "";
            } else {
                mTextBoxChordListVerdict.Text = mGrandStaffChordList.GetSelectedChord().GetVerdictText();
            }

            if (0 < mRealization.GetChordList().Count) {
                mButtonRemoveSelectedChord.IsEnabled = true;
                mComboBoxKey.IsEnabled = false;
                mGroupBoxMeter.IsEnabled = false;
                mTextBoxRealizationVerdict.Text = mGrandStaffRealization.GetSelectedChord().GetVerdictText();
            } else {
                mButtonRemoveSelectedChord.IsEnabled = false;
                mComboBoxKey.IsEnabled = true;
                mGroupBoxMeter.IsEnabled = true;
                mTextBoxRealizationVerdict.Text = "";
            }
        }

        private void UpdateVRelatedCheckBoxStatus() {
            // V和音が選択された時9の和音が選択可能になる。
            //                   根音省略形体が選択可能になる。
            // 短調の時、NaturalMinorが選択可能になる。
            if (mChordType.chordDegree == CD.V || mChordType.chordDegree == CD.V_V) {
                mRadioButtonChordFormNinth.IsEnabled = true;
                mCheckBoxOmitRoot.IsEnabled = true;
                if (mChordType.Is借用和音調は短調()) {
                    mCheckBoxNaturalMinor.IsEnabled = true;
                } else {
                    mCheckBoxNaturalMinor.IsChecked = false;
                    mCheckBoxNaturalMinor.IsEnabled = false;
                }
            } else {
                if (mRadioButtonChordFormNinth.IsChecked == true) {
                    mRadioButtonChordFormTriad.IsChecked = true;
                }
                mRadioButtonChordFormNinth.IsEnabled = false;
                mCheckBoxOmitRoot.IsChecked = false;
                mCheckBoxOmitRoot.IsEnabled = false;
                mCheckBoxNaturalMinor.IsChecked = false;
                mCheckBoxNaturalMinor.IsEnabled = false;
            }

            if (ChordListFactory.IsRaisedPossible(mChordType)) {
                mRadioButtonRaised.IsEnabled = true;
            } else {
                if (mRadioButtonRaised.IsChecked == true) {
                    mRadioButtonStandard.IsChecked = true;
                }
                mRadioButtonRaised.IsEnabled = false;
            }

            if (ChordListFactory.IsLoweredPossible(mChordType)) {
                mRadioButtonLowered.IsEnabled = true;
            } else {
                if (mRadioButtonLowered.IsChecked == true) {
                    mRadioButtonStandard.IsChecked = true;
                }
                mRadioButtonLowered.IsEnabled = false;
            }
        }
        private void UpdateAlteredRadioButtonStatus() {
            if (!mLoaded) {
                return;
            }

            // IV和音が選択された時付加和音が選択可能になる。
            if (mChordType.chordDegree == CD.IV) {
                mRadioButtonAddedTone6.IsEnabled = true;
                mRadioButtonAddedTone46.IsEnabled = true;
            } else {
                mRadioButtonAddedToneNone.IsChecked = true;
                mRadioButtonAddedTone6.IsEnabled = false;
                mRadioButtonAddedTone46.IsEnabled = false;
            }

            if (ChordListFactory.IsDorianPossible(mChordType)) {
                mRadioButtonDorianIV.IsEnabled = true;
            } else { 
                if (mRadioButtonDorianIV.IsChecked == true) {
                    mRadioButtonStandard.IsChecked = true;
                }
                mRadioButtonDorianIV.IsEnabled = false;
            }

            if (mChordType.chordDegree == CD.II) {
                mRadioButtonNapolitanII.IsEnabled = true;
            } else {
                if (mRadioButtonNapolitanII.IsChecked == true) {
                    mRadioButtonStandard.IsChecked = true;
                }
                mRadioButtonNapolitanII.IsEnabled = false;
            }
        }

        // 終止のラジオボタンが押せるか？
        private void UpdateTerminationRadioButtonStatus() {
            bool bEnableHalf      = false;
            bool bEnableDeceptive = false;
            bool bEnablePerfect   = false;
            bool bEnablePlagal    = false;

            if (1 < mRealization.GetChordList().Count) {
                var prevChord = mRealization.GetChord(mRealizationCanvas.GetFocusedIdx());
                var prevChordType = prevChord.ChordType;
                bEnableHalf = Progression.IsTerminationPossible(prevChordType, mChordType, TerminationType.Half);
                bEnableDeceptive = Progression.IsTerminationPossible(prevChordType, mChordType, TerminationType.Deceptive);
                bEnablePerfect = Progression.IsTerminationPossible(prevChordType, mChordType, TerminationType.Perfect);
                bEnablePlagal = Progression.IsTerminationPossible(prevChordType, mChordType, TerminationType.Plagal);
            }

            if ((!bEnableHalf && mRadioButtonTerminationHalf.IsChecked == true)
                    ||(!bEnablePerfect && mRadioButtonTerminationPerfect.IsChecked == true)
                    ||(!bEnablePlagal && mRadioButtonTerminationPlagal.IsChecked == true)
                    ||(!bEnableDeceptive && mRadioButtonTerminationDeceptive.IsChecked == true)) {
                mRadioButtonTerminationNone.IsChecked = true;
            }

            mRadioButtonTerminationHalf.IsEnabled = bEnableHalf;
            mRadioButtonTerminationPerfect.IsEnabled = bEnablePerfect;
            mRadioButtonTerminationPlagal.IsEnabled = bEnablePlagal;
            mRadioButtonTerminationDeceptive.IsEnabled = bEnableDeceptive;
        }

        private void OnMenuFileExitClicked(object sender, RoutedEventArgs e) {
            Close();
        }

        private string AskPath(bool bReadFile, string filter) {
            string ret = string.Empty;

            if (bReadFile) {
                var ofd = new OpenFileDialog();
                ofd.ReadOnlyChecked = true;
                ofd.Multiselect = false;
                ofd.Filter = filter;
                ofd.CheckPathExists = true;
                ofd.CheckFileExists = true;
                bool? dr = ofd.ShowDialog();
                if (true == dr) {
                    ret = ofd.FileName;
                }
            } else {
                var sfd = new SaveFileDialog();
                sfd.Filter = filter;
                sfd.CheckPathExists = false;
                sfd.CheckFileExists = false;
                bool? dr = sfd.ShowDialog();
                if (true == dr) {
                    ret = sfd.FileName;
                }
            }

            return ret;
        }

        private void OnMenuFileNewClicked(object sender, RoutedEventArgs e) {
            Title = ApplicationName;

            mComboBoxKey.SelectedIndex = 0;
            mChordType.musicKey = MusicKeyInfo.MainKeyCandidates[0];
            UpdateInternalKeyComboBox();
            UpdateBorrowedKeyComboBox();
            UpdateKeyRelatedCheckBoxState();

            mRealization = new Realization();

            mGrandStaffRealization.Update(GrandStaffControl.StaffType.Realization, mMeter, mRealization.GetChordList());
            UpdateChordList();
        }

        private void OnMenuFileOpenClicked(object sender, RoutedEventArgs e) {
            string readFilePath = AskPath(true, "FourPartHarmony Files|*.fph");
            if (string.Empty == readFilePath) {
                return;
            }

            var realization = RealizationSerializer.TryLoad2(readFilePath);
            if (realization == null) {
                return;
            }

            // 候補和音の調をロードした課題実施と一致させる。
            mChordType.musicKey = realization.GetChordList()[0].MusicKey;
            mComboBoxKey.SelectedIndex = Array.IndexOf(MusicKeyInfo.MainKeyCandidates, mChordType.musicKey);
            UpdateInternalKeyComboBox();
            UpdateBorrowedKeyComboBox();
            UpdateKeyRelatedCheckBoxState();

            mLastSaveFPHFilePath = readFilePath;
            Title = readFilePath + " " + ApplicationName;
            mRealization = null;
            mRealization = realization;
            mGrandStaffRealization.Update(GrandStaffControl.StaffType.Realization, mMeter, mRealization.GetChordList());
            UpdateChordList();
        }

        string mLastSaveFPHFilePath;

        private void OnMenuFileSaveAsClicked(object sender, RoutedEventArgs e) {
            if (mRealization.GetNumOfChords() < 1) {
                return;
            }

            string writeFilePath = AskPath(false, "FourPartHarmony Files (*.fph)|*.fph");
            if (string.Empty == writeFilePath) {
                return;
            }

            bool result = RealizationSerializer.TrySave2(mRealization, writeFilePath);
            if (result) {
                mLastSaveFPHFilePath = writeFilePath;
                Title = writeFilePath + " " + ApplicationName;
            }
        }

        private void RadioButtonChordDegree_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonCDI)    { mChordType.chordDegree = CD.I; }
            if (sender == mRadioButtonCDII)   { mChordType.chordDegree = CD.II; }
            if (sender == mRadioButtonCDIII)  { mChordType.chordDegree = CD.III; }
            if (sender == mRadioButtonCDIV)   { mChordType.chordDegree = CD.IV; }
            if (sender == mRadioButtonCDV)    { mChordType.chordDegree = CD.V; }
            if (sender == mRadioButtonCDVI)   { mChordType.chordDegree = CD.VI; }
            if (sender == mRadioButtonCDVII)  { mChordType.chordDegree = CD.VII; }
            if (sender == mRadioButtonCDVofV) { mChordType.chordDegree = CD.V_V; }

            if (!mLoaded) {
                return;
            }

            UpdateVRelatedCheckBoxStatus();

            UpdateAlteredRadioButtonStatus();

            UpdateTerminationRadioButtonStatus();

            UpdateChordList();
        }

        private void RadioButtonChordForm_Checked(object sender, RoutedEventArgs e) {
            if (!mLoaded) {
                return;
            }

            if (sender == mRadioButtonChordFormTriad) {
                mChordType.numberOfNotes = NumberOfNotes.Triad;

                // 第3転回不可。
                if (mRadioButtonInversion3rd.IsChecked == true) {
                    mRadioButtonInversionNone.IsChecked = true;
                }
                mRadioButtonInversion3rd.IsEnabled = false;
            }

            if (sender == mRadioButtonChordFormSeventh) {
                mChordType.numberOfNotes = NumberOfNotes.Seventh;
                mRadioButtonInversion3rd.IsEnabled = true;
            }

            if (sender == mRadioButtonChordFormNinth) {
                mChordType.numberOfNotes = NumberOfNotes.Ninth;
                mRadioButtonInversion3rd.IsEnabled = true;
            }

            UpdateChordList();
        }

        private void RadioButtonChordInversion_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonInversionNone) { mChordType.bassInversion = Inversion.根音; }
            if (sender == mRadioButtonInversion1st)  { mChordType.bassInversion = Inversion.第3音; }
            if (sender == mRadioButtonInversion2nd)  { mChordType.bassInversion = Inversion.第5音; }
            if (sender == mRadioButtonInversion3rd)  { mChordType.bassInversion = Inversion.第7音; }
            UpdateChordList();
        }

        private void RadioButtonChordPosition_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonChordPositionClose)  { mChordType.positionOfAChord = PositionOfAChord.密; }
            if (sender == mRadioButtonChordPositionOpen)   { mChordType.positionOfAChord = PositionOfAChord.開; }
            if (sender == mRadioButtonChordPositionOctave) { mChordType.positionOfAChord = PositionOfAChord.Oct; }
            UpdateChordList();
        }

        private void CheckBoxOmitRoot_CheckedChanged(object sender, RoutedEventArgs e) {
            mChordType.omission = (mCheckBoxOmitRoot.IsChecked == true) ? Omission.First : Omission.None;
            UpdateChordList();
        }

        private void RadioButtonAddedTone_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonAddedToneNone) { mChordType.addedTone = AddedToneType.None; }
            if (sender == mRadioButtonAddedTone6)    { mChordType.addedTone = AddedToneType.Six; }
            if (sender == mRadioButtonAddedTone46)   { mChordType.addedTone = AddedToneType.SixFour; }

            // +6付加和音によってドリアのIVが可能になるので。
            UpdateAlteredRadioButtonStatus();

            UpdateChordList();
        }

        private void CheckBoxBorrowedMinorChord_CheckedChanged(object sender, RoutedEventArgs e) {
            mChordType.is準固有 = (mCheckBoxBorrowedMinorChord.IsChecked == true);
            UpdateChordList();
        }

        private void RadioButtonMeter_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonMeter22) { mMeter = new MeterStruct(2, 2); }
            if (sender == mRadioButtonMeter44) { mMeter = new MeterStruct(4, 4); }
            UpdateChordList();
        }

        private void RadioButtonDuration_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonDurationWhole)   { mChordType.duration = DurationType.Whole; }
            if (sender == mRadioButtonDurationHalf)    { mChordType.duration = DurationType.Half; }
            if (sender == mRadioButtonDurationQuarter) { mChordType.duration = DurationType.Quarter; }
            if (sender == mRadioButtonDurationEighth)  { mChordType.duration = DurationType.Eighth; }
            UpdateChordList();
        }

        private void ComboBoxKey_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            if (!mLoaded || mComboBoxKey.SelectedIndex < 0) {
                return;
            }
            mChordType.musicKey = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];
            UpdateInternalKeyComboBox();
            UpdateBorrowedKeyComboBox();
            UpdateKeyRelatedCheckBoxState();
            UpdateChordList();
        }

        private void ComboBoxInternalKey_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            if (!mLoaded || mComboBoxInternalKey.SelectedIndex < 0) {
                return;
            }
            mChordType.musicKey    = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];
            mChordType.keyRelation = (KeyRelation)mComboBoxInternalKey.SelectedIndex;

            UpdateBorrowedKeyComboBox();
            UpdateKeyRelatedCheckBoxState();
            UpdateChordList();
        }

        private void ComboBoxBorrowedKey_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            if (!mLoaded || mComboBoxBorrowedKey.SelectedIndex < 0) {
                return;
            }
            mChordType.musicKey    = MusicKeyInfo.MainKeyCandidates[mComboBoxKey.SelectedIndex];
            mChordType.keyRelation = (KeyRelation)mComboBoxInternalKey.SelectedIndex;
            mChordType.borrowedKeyRelation = (KeyRelation)mComboBoxBorrowedKey.SelectedIndex;

            UpdateKeyRelatedCheckBoxState();
            UpdateChordList();
        }

        private void ChordListCanvas_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            mGrandStaffChordList.OnTouch(e.GetPosition(mChordListCanvas));
        }

        private void ChordListCanvas_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            mChordPlayer.Stop();
        }
        private void ChordListCanvas_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) {
            mChordPlayer.Stop();
        }


        private void RealizationCanvas_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            mGrandStaffRealization.OnTouch(e.GetPosition(mRealizationCanvas));
            UpdateChordList();
        }

        private void RealizationCanvas_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            mChordPlayer.Stop();
        }

        private void ButtonAddSelectedChord_Click(object sender, RoutedEventArgs e) {
            var c = mGrandStaffChordList.GetSelectedChord();
            mRealization.Insert(mGrandStaffRealization.GetSelectedChordIdx()+1, c, true);
            mGrandStaffRealization.Update(GrandStaffControl.StaffType.Realization, mMeter, mRealization.GetChordList());
            mGrandStaffRealization.SetSelectedChordIdx(mGrandStaffRealization.GetSelectedChordIdx() + 1);
            UpdateChordList();

        }

        private void ButtonRemoveSelectedChord_Click(object sender, RoutedEventArgs e) {
            mRealization.DeleteChordAt(mGrandStaffRealization.GetSelectedChordIdx());
            mGrandStaffRealization.Update(GrandStaffControl.StaffType.Realization, mMeter, mRealization.GetChordList());
            UpdateChordList();
        }

        private void CheckBoxNaturalMinor_CheckedChanged(object sender, RoutedEventArgs e) {
            mChordType.has固有VII = (mCheckBoxNaturalMinor.IsChecked == true);
            UpdateChordList();
        }

        private void OnMenuMidiSettingsClicked(object sender, RoutedEventArgs e) {
            var w = new MidiSettingsWindow(mMidiOutput.GetUseDeviceId(), mChordPlayer.GetVelocity());
            var result = w.ShowDialog();

            if (result != true) {
                return;
            }

            mChordPlayer.SetVelocity(w.Velocity);
            mMidiOutput.Close();
            mMidiOutput.Open(w.SelectedDeviceId);
        }

        private void OnMenuMidiSendResetClicked(object sender, RoutedEventArgs e) {
            mMidiOutput.SendReset();
        }

        private void RadioButtonTermination_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonTerminationNone) { mChordType.termination = TerminationType.None; }
            if (sender == mRadioButtonTerminationHalf) { mChordType.termination = TerminationType.Half; }
            if (sender == mRadioButtonTerminationPerfect) { mChordType.termination = TerminationType.Perfect; }
            if (sender == mRadioButtonTerminationPlagal) { mChordType.termination = TerminationType.Plagal; }
            if (sender == mRadioButtonTerminationDeceptive) { mChordType.termination = TerminationType.Deceptive; }
            UpdateChordList();
        }

        private void RadioButtonAlteration_Checked(object sender, RoutedEventArgs e) {
            if (sender == mRadioButtonStandard) { mChordType.alteration = AlterationType.None; }
            if (sender == mRadioButtonDorianIV) { mChordType.alteration = AlterationType.Dorian; }
            if (sender == mRadioButtonNapolitanII) { mChordType.alteration = AlterationType.Naples; }
            if (sender == mRadioButtonRaised) { mChordType.alteration = AlterationType.Raised; }
            if (sender == mRadioButtonLowered) { mChordType.alteration = AlterationType.Lowered; }
            UpdateChordList();
        }

    }
}
